IBX-10186 Add $limit Option to Count #413
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



v3.3Warning
This PR contains all of the changes from #412 verbatim. Please read the description of that PR for relevant details of changes from that branch.
What
This PR continues the work started in IBX-10174 by adding a $limit clause to
LocationService::countandContentService::countcount. The Public facing API's have been changed accordingly.The changes to the public API this PR specifically makes are:
To the following:
This opens up the ability to limit the total item count pulled back from the DB and proportionally cuts down on overall processing times.
This is especially useful for when:
How
Based on the above API changes most top level repository
countqueries have a limit option. A new trait has been added for converting SQL Like:to
It should be noted that the count query does not change until a limit is directly passed. Given by default this is set to
nullno underlying queries made by current sites will change unless a limit is passed meaning this PR should result in no BC breaksWhy
Performance of eZ Platform Count queries (Given the number of required joins and existing database schema) scale poorly, especially in cases where many content items match the given count query. This is exacerbated when the associated user has a larger set of permissions
From benchmarking here is how eZ Scales to a location count query with no limitations .

As you can see the number of items pulled back is directly proportional the time the query takes to resolve. (The red dot representing the current implementation). In the CMS many such queries are made to generate pages over the lifespan of the request. Many of which can be satisfied with limits of 1 or a lower number.
For our use case the effect of these queries are so catastrophic the CMS is completely unusable / some pages take 10+ seconds to load. (Most of this can be attributed to IBX-10186 and IBX-10174)
This trend gets even worse with the eZ Permissions system where Count queries can quickly spiral into the single limiting factor in overall page performance. (See below a chat like above be the query is bounded by some more specific permissions)

Checklist:
$ composer fix-cs).@ezsystems/engineering-team).